<?php

class Me extends Controller {


	function index()
	{
		$me = $this->MUser->get(Auth::$user_id);
		$filters = array('user_id' => $me['id'], 'sort' => 'num asc,date asc,id asc');
		$me['operations'] = $this->MOper->getList($filters);
		$all_mavro = $this->MOper->getMavroSumm(array($me['id']));
		$me['all_mavro'] = @$all_mavro[$me['id']];

		$users = array($me['id'] => $me);

		$users_referer = array();
		if(count($me['operations']))
		{
			$referer = $this->MUser->getFirstRow(array('email' => $me['referer_email']));
			if(@$referer['id'])
			{
				$filters_referer = array('user_id' => $referer['id'], 'type' => 'ref', 'parent_id' => array_keys($me['operations']), 'sort' => 'date asc,id asc');
				$referer['operations'] = $this->MOper->getList($filters_referer);
				$referer_all_mavro = $this->MOper->getMavroSumm(array($referer['id']), array_keys($referer['operations']));
				$referer['all_mavro'] = $referer_all_mavro[$referer['id']];

				if(count($referer['operations']))
				{
					$users_referer = array($referer['id'] => $referer);
				}
			}
		}


		$this->load->view('head', array());
		$this->load->view('oper/me', array('users' => $users, 'users_referer' => $users_referer));
		$this->load->view('foot');
	}


}

